# Maintainer: Jelle van der Waa <jelle@archlinux.org>
# Contributor:  Konstantin Gorodinskii <mail@konstantin.io>

pkgname=wabt
pkgdesc="The WebAssembly Binary Toolkit is a suite of tools for WebAssembly"
url="https://github.com/WebAssembly/wabt"
pkgver=1.0.32
pkgrel=1
arch=('loong64' 'x86_64')
license=('APACHE')
depends=(glibc gcc-libs)
makedepends=('cmake' 'git' 'gcc' 'clang' 'python-ply' 'gtest')
source=("git+https://github.com/WebAssembly/wabt#commit=366a86a119727bdc957c2bf988ebd835c3ddb256"
        "git+https://github.com/WebAssembly/testsuite"
        "git+https://github.com/google/googletest"
        "git+https://github.com/dabeaz/ply")
validpgpkeys=('5DE3E0509C47EA3CF04A42D34AEE18F83AFDEB23')
md5sums=('SKIP'
         'SKIP'
         'SKIP'
         'SKIP')

prepare() {
  cd ${pkgname}

  git submodule init
  git config submodule."external/testsuite".url "${srcdir}/testsuite"
  git config submodule."external/googletest".url "${srcdir}/googletest"
  git config submodule."external/ply".url "${srcdir}/ply"
  git submodule update --recursive

  mkdir build
}

build() {
  cd ${pkgname}/build
  export CFLAGS+=" -ffat-lto-objects"
  cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=Release \
    ..

  make
}

check() {
  cd ${pkgname}
#  make test
}

package() {
  cd ${pkgname}/build
  make DESTDIR="${pkgdir}" install
}
